<template>
  <div class="app-container" ref="appcontainer">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备编号" prop="instrumentNumber">
        <el-input v-model="queryParams.instrumentNumber" placeholder="请输入设备编号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="设备名称" prop="instrumentName">
        <el-input v-model="queryParams.instrumentName" placeholder="请输入设备名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.openStatus" placeholder="请选择状态" clearable size="small">
          <el-option v-for="item in gc_instrument_state_options" :key="item.dictValue" :label="item.dictLabel"
            :value="item.dictValue"></el-option>
        </el-select>
      </el-form-item>
      
      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain icon="" size="mini" @click="handleImport">导入
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" :loading="exportLoading"
          @click="handleExport">导出</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain

          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          
        >删除</el-button>
      </el-col>


      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :height="tableHeight" :data="instrumentList" :row-class-name="tableRowClassName"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="30" align="center" show-overflow-tooltip />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="设备编号" align="center" prop="instrumentNumber" />
      <el-table-column label="名称" align="center" prop="instrumentName" />
      <el-table-column label="规格型号" align="center" prop="specification" />
      <el-table-column label="铭牌号" align="center" prop="brandNumber" />
      <el-table-column label="测量范围" align="center" prop="measuringRange" />
      <el-table-column label="溯源方式" align="center" prop="traceabilityType" />
      <!-- <el-table-column label="证书编号" align="center" prop="certificateNo" /> -->
      <el-table-column label="校准日期" align="center" prop="verificationTime" width="180">
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.verificationTime, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="检定单位" align="center" prop="verificationUnit" />-->
      <el-table-column label="下次校准日期" align="center" prop="nextTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.nextTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="溯源有效期" align="center" prop="traceabilityPeriod" />
      <el-table-column label="生产厂家" align="center" prop="manufacturer" />
      <el-table-column label="存放位置" align="center" prop="position" />
      <el-table-column label="状态" align="center" prop="openStatus" />
        
      <!-- <el-table-column label="数量" align="center" prop="number" />
      <el-table-column label="设备单价" align="center" prop="devicePrice" />
      <el-table-column label="销售单位" align="center" prop="salesUnit" />
      <el-table-column label="固定资产编号" align="center" prop="fixedNumber" />
      <el-table-column label="发票日期" align="center" prop="invoiceTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.invoiceTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设备/配件" align="center" prop="itemType" /> -->
      <el-table-column label="部门
" align="center" prop="department" />
      <el-table-column label="
启用日期" align="center" prop="enableTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.enableTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设备用途" align="center" prop="purpose">
           <!-- <template slot-scope="scope">
          <span v-for="item in scope.row.purposeList" :key="item.id">{{ item.name}}</span>
        </template> -->
      </el-table-column>
      <!-- <el-table-column label="合格证文件" align="center" prop="certificateFile" />
      <el-table-column label="发票文件" align="center" prop="invoiceFile" /> -->
      <!-- <el-table-column label="说明书文件" align="center" prop="instructionsFile" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!--          <el-button size="mini" type="text" @click="handleAccept(scope.row)">领用</el-button>-->
          <el-button size="mini" type="text" @click="handleUpdate(scope.row)">编辑</el-button>
          <el-button size="mini" type="text" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 仪器领用 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="lyopen" width="500px" append-to-body>
      <el-row class="mb-10">
        <el-col :span="12" class="mb10">
          <span class="text-size">设备编号:</span>
          <span class="text-size">11</span>
        </el-col>
        <el-col :span="12">
          <span class="text-size">名称:</span>
          <span class="text-size">11</span>
        </el-col>
      </el-row>
      <el-row class="mb-10">
        <el-col :span="12">
          <span class="text-size">规格型号:</span>
          <span class="text-size">11</span>
        </el-col>
        <el-col :span="12">
          <span class="text-size">设备铭牌号:</span>
          <span class="text-size">11</span>
        </el-col>
      </el-row>
      <el-row class="mb-10">
        <el-col :span="12">
          <span class="text-size">测量范围:</span>
          <span class="text-size">11</span>
        </el-col>
        <el-col :span="12">
          <span class="text-size">溯源方式:</span>
          <span class="text-size">11</span>
        </el-col>

      </el-row>
      <el-row class="mb-10">
        <el-col :span="12">
          <span class="text-size">检定单位:</span>
          <span class="text-size">11</span>
        </el-col>
        <el-col :span="12">
          <span class="text-size">证书编号:</span>
          <span class="text-size">11</span>
        </el-col>

      </el-row>
      <el-row class="mb-10">
        <el-col :span="12">
          <span class="text-size">检定日期:</span>
          <span class="text-size">11</span>
        </el-col>
        <el-col :span="12">
          <span class="text-size">下次检定日期:</span>
          <span class="text-size">11</span>
        </el-col>

      </el-row>
      <el-row class="mb-10">
        <el-col :span="12">
          <span class="text-size">溯源有效期:</span>
          <span class="text-size">11</span>
        </el-col>
        <el-col :span="12">
          <span class="text-size">生产厂家:</span>
          <span class="text-size">11</span>
        </el-col>

      </el-row>
      <el-row class="mb-10">
        <el-col :span="12">
          <span class="text-size">存放位置:</span>
          <span class="text-size">11</span>
        </el-col>
        <el-col :span="12">
          <span class="text-size">数量:</span>
          <span class="text-size">11</span>
        </el-col>

      </el-row>
      <el-row class="mb-10">
        <el-col :span="12">
          <span class="text-size">设备单价:</span>
          <span class="text-size">11</span>
        </el-col>
        <el-col :span="12">
          <span class="text-size">销售单位:</span>
          <span class="text-size">11</span>
        </el-col>

      </el-row>
      <el-row class="mb-10">
        <el-col :span="12">
          <span class="text-size">发票日期:</span>
          <span class="text-size">11</span>
        </el-col>
        <el-col :span="12">
          <span class="text-size">销固定资产编号:</span>
          <span class="text-size">11</span>
        </el-col>

      </el-row>
      <el-row class="mb-10">
        <el-col :span="12">
          <span class="text-size">设备/配件:</span>
          <span class="text-size">11</span>
        </el-col>
        <el-col :span="12">
          <span class="text-size">所属部门:</span>
          <span class="text-size">11</span>
        </el-col>
      </el-row>
      <el-row class="mb-10">
        <el-col :span="12">
          <span class="text-size">启用日期:</span>
          <span class="text-size">11</span>
        </el-col>
        <el-col :span="12">
          <span class="text-size">合格证复印件:</span>
          <span class="text-size">11</span>
        </el-col>
      </el-row>
      <el-row class="mb-10">
        <el-col :span="12">
          <span class="text-size">发票复印件:</span>
          <span class="text-size">11</span>
        </el-col>
        <el-col :span="12">
          <span class="text-size">设备使用说明书:</span>
          <span class="text-size">11</span>
        </el-col>
      </el-row>
      <el-row class="mb-10">
        <el-col :span="12">
          <span class="text-size">领用日期:</span>
          <span class="text-size">11</span>
        </el-col>
        <el-col :span="12">
          <el-form-item label="归还日期" prop="nextTime">
            <el-date-picker clearable size="small" v-model="ghdate" type="date" value-format="yyyy-MM-dd"
              placeholder="归还日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm1">领用</el-button>
        <!-- <el-button @click="cancel">取 消</el-button> -->
      </div>
    </el-dialog>

    <!-- 添加或修改仪器信息对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="设备编号" prop="instrumentNumber">
          <el-input v-model="form.instrumentNumber" placeholder="请输入仪器编号" />
        </el-form-item>
        <el-form-item label="设备名称" prop="instrumentName">
          <el-input v-model="form.instrumentName" placeholder="请输入仪器名称" />
        </el-form-item>
        <el-form-item label="规格型号" prop="specification">
          <el-input v-model="form.specification" placeholder="请输入规格型号" />
        </el-form-item>
        <el-form-item label="设备铭牌号" prop="brandNumber">
          <el-input v-model="form.brandNumber" placeholder="请输入设备铭牌号" />
        </el-form-item>
        <el-form-item label="测量范围" prop="measuringRange">
          <el-input v-model="form.measuringRange" placeholder="请输入测量范围" />
        </el-form-item>
        <el-form-item label="溯源方式" prop="traceabilityType">
          <el-select v-model="form.traceabilityType" placeholder="请选择溯源方式">
            <el-option v-for="dict in traceabilityTypeOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictValue" />
          </el-select>
        </el-form-item>
        <el-form-item label="校准单位" prop="verificationUnit">
          <el-input v-model="form.verificationUnit" placeholder="请输入校准单位" />
        </el-form-item>
        <el-form-item label="证书编号" prop="certificateNo">
          <el-input v-model="form.certificateNo" placeholder="请输入证书编号" />
        </el-form-item>
        <el-form-item label="校准日期" prop="verificationTime">
          <el-date-picker clearable size="small" v-model="form.verificationTime" type="date" value-format="yyyy-MM-dd"
            placeholder="选择校准日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="下个校准日期" prop="nextTime">
          <el-date-picker clearable size="small" v-model="form.nextTime" type="date" value-format="yyyy-MM-dd"
            placeholder="选择下个校准日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="溯源有效期" prop="traceabilityPeriod">
          <el-input v-model="form.traceabilityPeriod" placeholder="请输入溯源有效期" />
        </el-form-item>
        <el-form-item label="生产厂家" prop="manufacturer">
          <el-input v-model="form.manufacturer" placeholder="请输入生产厂家" />
        </el-form-item>
        <el-form-item label="存放位置" prop="position">
          <el-input v-model="form.position" placeholder="请输入存放位置" />
        </el-form-item>

        <!-- <el-form-item label="创建来源" prop="createType">
          <el-select v-model="form.createType" placeholder="请选择创建来源">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item> -->

        <!-- <el-form-item label="更新来源" prop="updateType">
          <el-select v-model="form.updateType" placeholder="请选择更新来源">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item> -->

        <!-- <el-form-item label="数量" prop="number">
          <el-input v-model="form.number" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="设备单价" prop="devicePrice">
          <el-input v-model="form.devicePrice" placeholder="请输入设备单价" />
        </el-form-item>
        <el-form-item label="销售单位" prop="salesUnit">
          <el-input v-model="form.salesUnit" placeholder="请输入销售单位" />
        </el-form-item>
        <el-form-item label="发票日期" prop="invoiceTime">
          <el-date-picker clearable size="small" v-model="form.invoiceTime" type="date" value-format="yyyy-MM-dd"
            placeholder="选择发票日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="固定资产编号" prop="fixedNumber">
          <el-input v-model="form.fixedNumber" placeholder="请输入固定资产编号" />
        </el-form-item>

        <el-form-item label="设备/配件" prop="itemType">
          <el-select v-model="form.itemType" placeholder="请选择物品类型">
            <el-option v-for="dict in instrumentTypeOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictValue" />
          </el-select>
        </el-form-item> -->
        <el-form-item label="所属部门
" prop="department">
          <el-input v-model="form.department" placeholder="请输入部门
" />
        </el-form-item>

        <el-form-item label="启用/报废/库存" >
          <el-select v-model="form.openStatus" placeholder="请选择启用/报废/库存" >
            <el-option v-for="dict in gc_instrument_state_options" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictLabel" />
          </el-select>
        </el-form-item>

        <el-form-item label="
启用日期" prop="enableTime">
          <el-date-picker clearable size="small" v-model="form.enableTime" type="date" value-format="yyyy-MM-dd"
            placeholder="选择
启用日期">
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="合格证文件">
          <fileUpload v-model="form.certificateFile" />
        </el-form-item> -->
        <el-form-item label="校准证书">
          <fileUpload v-model="form.invoiceFile" />
        </el-form-item>
        <!-- <el-form-item label="设备使用说明书">
          <fileUpload v-model="form.instructionsFile" />
        </el-form-item> -->
        <el-form-item label="设备用途" prop="itemType">
          <el-select v-model="form.purpose" placeholder="请选择实验项目" multiple collapse-tags>
            <el-option v-for="dict in sampleProjectOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :value="dict.dictLabel" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 仪器导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!-- <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的仪器数据
          </div> -->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <!-- <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importInstrumentTemplate">下载模板</el-link> -->
          <a :href="file1Url" download="仪器设备导入模板.xlsx" style="list-style: none;color: #1176FF;">模版下载</a>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>


<script>
import file1Url from '@/assets/download/仪器设备导入模板.xlsx';
import {
  listInstrument,
  getInstrument,
  logicDelInstrument,
  addInstrument,
  updateInstrument,
  exportInstrument, importInstrumentTemplate,
} from "@/api/system/instrument";
import * as XLSX from 'xlsx';
import { getToken } from "@/utils/auth";
export default {
  name: "Instrument",
  data() {
    return {
      file1Url,
      loading: false,
      // 导入遮罩层
      importLoading: false,
      excelData: {
        header: null,
        results: null
      },
      lyopen: false,
      tableHeight: 0,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      ghdate: '',//归还日期
      ids: [],     // 选中数组
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 仪器信息表格数据
      instrumentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      statusOptions: [],
      statusArr:[],
      instrumentTypeOptions: [],
      sampleProjectOptions: [],
      traceabilityTypeOptions: [],
      headers: { Authorization: "Bearer " + getToken() },
      uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload",

      // 仪器导入参数
      upload: {
        // 是否显示弹出层（仪器导入）
        open: false,
        // 弹出层标题（仪器导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的仪器数据
        updateSupport: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/instrument/instrument/importData"
      },

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: null,
        instrumentNumber: null,
        instrumentName: null,
        specification: null,
        brandNumber: null,
        measuringRange: null,
        traceabilityType: null,
        certificateNo: null,
        verificationTime: null,
        verificationUnit: null,
        nextTime: null,
        traceabilityPeriod: null,
        manufacturer: null,
        position: null,
        number: null,
        devicePrice: null,
        salesUnit: null,
        fixedNumber: null,
        invoiceTime: null,
        itemType: null,
        department: null,
        enableTime: null,
        certificateFile: null,
        invoiceFile: null,
        instructionsFile: null,
        purpose: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
         instrumentNumber: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        instrumentName:[{
           required: true, message: "不能为空", trigger: "blur"
        }],
        // itemType:[{
        //    required: true, message: "请选择", trigger: "blur"
        // }],

      },
      gc_instrument_state_options:[],
      gc_instrument_state:[],
    };

  },
  created() {
    //状态
    this.getDicts("gc_instrument_state").then((response) => {
      let data = response.data;
      let new_arr = [];
      data.forEach(function (item) {
        new_arr[item.dictValue] = item.dictLabel;
      });
      this.gc_instrument_state_options = data
      this.gc_instrument_state = new_arr;
    });


    this.getList();
    this.calHeight();
    this.getstatus();
    this.getSampleProject();
    this.getInstrumentType();
    this.getTraceabilityType();
    
  },
  watch: {
    showSearch: "calHeight",
  },
  methods: {

    readExcel(file) {
      return new Promise((resolve, reject) => {
        if (file instanceof File) {
          const reader = new FileReader();

          reader.onloadend = (progressEvent) => {
            const arrayBuffer = reader.result;
            console.log(arrayBuffer, 'arrayBuffer')

            const options = { type: 'array' };
            const workbook = XLSX.read(arrayBuffer, options);

            const sheetName = workbook.SheetNames[0];
            const sheet = workbook.Sheets[sheetName];
            const jsonData = XLSX.utils.sheet_to_json(sheet);
            console.log(jsonData, 'jsonData111')

            // 转换数据格式以匹配表格字段
            const formattedData = jsonData.map(item => ({
              instrumentNumber: item['设备编号'] || '',
              instrumentName: item['设备名称'] || '',
              specification: item['规格型号'] || '',
              brandNumber: item['名牌号'] || '',
              measuringRange: item['测量范围'] || '',
              traceabilityType: item['溯源方式'] || '',
              certificateNo: item['证书编号'] || '',
              verificationTime: item['检定日期'] || '',
              nextTime: item['下次检定日期'] || '',
              traceabilityPeriod: item['溯源有效期'] || '',
              manufacturer: item['生产厂家'] || '',
              position: item['存放位置'] || '',
              status: item['状态'] || '',
              number: item['数量'] || '',
              devicePrice: item['设备单价'] || '',
              salesUnit: item['销售单位'] || '',
              fixedNumber: item['固定资产编号'] || '',
              invoiceTime: item['发票日期'] || '',
              itemType: item['设备/配件'] || '',
              department: item['部门'] || '',
              enableTime: item['启用日期'] || '',
              certificateFile: item['合格证文件'] || '',
              invoiceFile: item['发票文件'] || '',
              instructionsFile: item['说明书文件'] || '',
              purpose: item['设备用途'] || '',

            }));

            resolve(formattedData);
          };
          reader.readAsArrayBuffer(file);
        } else {
          reject(new Error('入参不是 File 类型'));
        }
      });
    },
 tableRowClassName({row, rowIndex}) {
    console.log(row,rowIndex,'111')
        if (rowIndex === 1) {
          return 'warning-row';
        } else if (rowIndex === 3) {
          return 'success-row';
        }
        return '';
      },
    handlAcept() {
      this.$refs.fileInput.click();
    },
    async handleFileUpload(e) {
      const file = e.target.files[0];
      if (!file) return;

      // 检查文件类型
      const fileTypes = ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel'];
      if (!fileTypes.includes(file.type)) {
        this.$message.error('请上传Excel文件');
        return;
      }

      this.importLoading = true;
      try {
        const data = await this.readExcel(file);
        if (!data || data.length === 0) {
          throw new Error('Excel文件中没有有效数据');
        }

        // 批量导入数据
        for (const item of data) {
          await addInstrument(item);
        }

        this.$message.success(`成功导入${data.length}条数据`);
        this.getList(); // 刷新表格数据
      } catch (err) {
        console.error('导入失败:', err);
        this.$message.error(err.message || '导入失败');
      } finally {
        this.importLoading = false;
        e.target.value = '';
      }
    },

    //仪器状态
    getstatus() {
      this.getDicts("instrument_state").then(response => {
        let data = response.data
        this.statusOptions = data;
        let new_arr = [];
        data.forEach(function (item) {
          new_arr[item.dictValue] = item.dictLabel
        });
        this.statusArr = new_arr;

      });
    },

    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },

    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "仪器导入";
      this.upload.open = true;
    },

    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },

    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();


    },

    /** 下载模板操作 */
    importInstrumentTemplate() {
      importInstrumentTemplate().then(response => {
        this.download(response.msg);
      });
    },
    getSampleProject() {
      this.getDicts("detection_item_indoor").then(response => {
        this.sampleProjectOptions = this.sampleProjectOptions.concat(response.data);
      });
      this.getDicts("detection_item_scene").then(response => {
        this.sampleProjectOptions = this.sampleProjectOptions.concat(response.data);
      })
    },
    getInstrumentType() {
      this.getDicts("instrument_type").then(response => {
        this.instrumentTypeOptions = response.data;
      });
    },
    getTraceabilityType() {
      this.getDicts("gc_instrument_shuyaun").then(response => {
        console.log("ddd")
        console.log(response.data)
        this.traceabilityTypeOptions = response.data;
      });
    },

    submitForm1() { },
    calHeight() {
      this.$nextTick(() => {
        const rect = this.$refs.appcontainer.getBoundingClientRect();
        let height = this.$refs.queryForm.$el.offsetHeight;
        this.tableHeight = rect.height - height - 120;
      });
    },
    /** 查询仪器信息列表 */
    getList() {
      this.loading = true;
      listInstrument(this.queryParams).then((response) => {
        this.instrumentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createTime: null,
        updateTime: null,
        delState: null,
        delUser: null,
        delType: null,
        delTime: null,
        createBy: null,
        createType: null,
        updateBy: null,
        updateType: null,
        status: 0,
        instrumentNumber: null,
        instrumentName: null,
        specification: null,
        brandNumber: null,
        measuringRange: null,
        traceabilityType: null,
        certificateNo: null,
        verificationTime: null,
        verificationUnit: null,
        nextTime: null,
        traceabilityPeriod: null,
        manufacturer: null,
        position: null,
        number: null,
        devicePrice: null,
        salesUnit: null,
        fixedNumber: null,
        invoiceTime: null,
        itemType: null,
        department: null,
        enableTime: null,
        certificateFile: null,
        invoiceFile: null,
        instructionsFile: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.showSearch = true;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加仪器信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset();
      const id = row.id || this.ids;
      getInstrument(id).then((response) => {
        this.form = response.data;
       if (response.data.purpose) {
          this.form.purpose = response.data.purpose.split(',')
        } else {
          this.form.purpose = [];
        }
        this.open = true;
        this.title = "修改仪器信息";
      });
    },
    //领用
    handleAccept() {
      this.title = '仪器领用'
      this.lyopen = true
    },
    /** 提交按钮 */
    submitForm() {
      this.form.purpose = this.form.purpose.toString()
      console.log('form', this.form.purpose)
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateInstrument(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInstrument(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm("是否确认删除?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return logicDelInstrument(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      const ids = this.ids;
      console.log(ids);
      this.queryParams.ids = ids;
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有仪器信息数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportInstrument(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => { });
    },
  }
};
</script>
<style scoped>
  .el-table tr .warning-row {
    background: rgb(183, 162, 124);
  }

  .el-table .success-row {
    background: #9edd7c;
  }
.mb-10 {
  margin-bottom: 1%;
}
</style>
